//
//  SearchBuyView.m
//  GYDemo
//
//  Created by Mrzhang on 2018/4/11.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "SearchBuyView.h"
#import "GYSearchViewModel.h"
#import "Head.h"
@interface SearchBuyView ()<UITableViewDelegate,UITableViewDataSource>
{
    NSInteger currentPage;
}
@property(nonatomic,strong)NSMutableDictionary* paraDataSource;
@property (nonatomic,strong)GYSearchViewModel *likeProductInfoviewModel;
@end
@implementation SearchBuyView

-(GYSearchViewModel *)likeProductInfoviewModel
{
    if (!_likeProductInfoviewModel) {
        _likeProductInfoviewModel=[[GYSearchViewModel alloc] init];
    }
    return _likeProductInfoviewModel;
}
-(NSMutableDictionary *)paraDataSource{
    
    if (!_paraDataSource) {
        _paraDataSource=[[NSMutableDictionary alloc] init];
    }
    return _paraDataSource;
}
-(UITableView *)myTable
{
    if (!_myTable) {
        _myTable=[[GCBaseTableView alloc]initWithFrame:self.bounds style:UITableViewStyleGrouped];
        _myTable.delegate=self;
        _myTable.dataSource=self;
        _myTable.separatorStyle=UITableViewCellSeparatorStyleSingleLine;
        _myTable.backgroundColor=Main_Color_BG;
        _myTable.backgroundColor=[UIColor whiteColor];
    
    }
    return _myTable;
}



-(instancetype)initWithFrame:(CGRect)frame
{
    self=[super initWithFrame:frame];
    if (self)
    {
        
        [self addSubview:self.myTable];
    }
    return self;
}


#pragma mark - delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.likeProductInfoviewModel.buyArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellID = @"CellIDThird";
    GYBuyListCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID];
    if (cell == nil) {
        cell = [[GYBuyListCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        // @WeakSelf
    }
    GYHomeBuyProductInfoModel *model = self.likeProductInfoviewModel.buyArr[indexPath.row];
    cell.model = model;

  //  @WeakSelf;
    [cell.offerBtn handleControlEvent:UIControlEventTouchUpInside withBlock:^{
//        GYHomeBuyDetailVC* gy=[[GYHomeBuyDetailVC alloc] init];
//        gy.passID=[NSString stringWithFormat:@"%@",model.id];
//        [selfp.navigationController pushViewController:gy animated:YES];
        _callback(model.id);

    }];
    
    
    
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat height = WFCGFloatY(104);
    return height;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView* view=[UIView new];
    return view;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return .0001f;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return nil;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.001f;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    GYHomeBuyProductInfoModel *model = self.likeProductInfoviewModel.buyArr[indexPath.row];
    _callback(model.id);
}

-(void)refresh:(GYSearchViewModel *)model
{
    self.likeProductInfoviewModel=model;
    [_myTable reloadData];
}


@end
